package ywh.manager
{
	import ywh.utils.DataLoader;
	import ywh.utils.XMLUtils;
	
	/**
	 * 课程数据信息类;
	 * @author 杨伟华
	 * @version 1.0
	 *
	 * Created 1/21/2013 9:44 AM
	 */
	public class DataInfo
	{
		private var _playerInfos:XMLList;
		private var _listInfos:XMLList;
		private var _streamInfos:XMLList;
		
		private var _chapterPath:String;
		private var _listBasePath:String;
		
		static private var _$:DataInfo;
		
		public function DataInfo(p:PrivateClass)
		{
			if (!p || _$)
			{
				throw(new Error("DataInfo是一个单例类，请调用DataInfo.$"));
			}
			else
			{
				_$ = this;
			}
		}
		
		static public function get $():DataInfo
		{
			return _$ ||= new DataInfo(new PrivateClass());
		}
		 
		static public function clear$():void {
			_$ = null;
		}
		
		/**
		 * 加载一个URL到
		 * @param	url
		 * @param	chapterPath
		 */
		public function loadURL(url:String):void
		{
			_playerInfos = null;
			_listInfos = null;
			_streamInfos = null;
			_listBasePath = null;
			DataLoader.addData(Core.getResolvePath(url), parseData,this);
		}
		
		/**
		 * 获取章节目录;
		 */
		public function get chapterPath():String
		{
			return _chapterPath;
		}
		
		/**
		 * 获取列表系列的基准路径;
		 * @param	setIndex
		 * @return
		 */
		public function get listBasePath():String
		{
			return _listBasePath;
		}
		
		/**
		 * 获取所有的播放器信息列表;
		 */
		public function get playerInfos():XMLList
		{
			return _playerInfos;
		}
		
		/**
		 * 获取所有的媒体列表信息;
		 */
		public function get listInfos():XMLList
		{
			return _listInfos;
		}
		
		public function get streamInfos():XMLList
		{
			return _streamInfos;
		}
		
		private function parseData(data:String,target:Object):void
		{
			var xml:XML = new XML(data);
			_playerInfos = xml[Tag.PLAYER_SET][Tag.PLAYER];
			_listInfos = xml[Tag.LIST_SET][Tag.LIST];
			_streamInfos = xml[Tag.STREAM_SET][Tag.STREAM];
			_listBasePath = XMLUtils.getPropString(xml[Tag.LIST_SET][0], Tag._PARH);
			Core.state = CoreState.INIT_DATA_LOADED;
		}
	}
}

class PrivateClass
{
}